### preprocessing

# rate for evaluation
test.group.rate: test.group new_index.txt KDD_Track1_solution.csv
	python eval-python/mktestrate.py test.group new_index.txt KDD_Track1_solution.csv test.group.rate

# user labels, for grouping results
user.empty.labels: user_profile.ridx
	pypy python/gen_user_label_empty.py $+ $@

# user grouped random order file, used to generate user grouped format
train.group.order: train.ridx
	svdpp_randorder train.ridx train.group.order
# training data reordered in user grouped format
train.group: train.ridx train.group.order
	line_reorder train.ridx train.group.order train.group

# user grouped random order file, used to generate user grouped format
test.group.order: test.ridx
	svdpp_randorder test.ridx test.group.order
# testing data reordered in user grouped format
test.group: test.ridx test.group.order
	line_reorder test.ridx test.group.order test.group

## filters

# purge filter
train.purge.filter: train.ridx
	java -cp java/track1-tlp.jar tlp.preprocessing.DuplicatesRemover -filter -RmNegDuplicates -purge -in train.ridx -out train.purge.filter

train.purge.group.filter: train.purge.filter train.group.order
	line_reorder train.purge.filter train.group.order train.purge.group.filter

test.purge.filter: test.ridx
	java -cp java/track1-tlp.jar tlp.preprocessing.DuplicatesRemover -filter -RmNegDuplicates -purge -in test.ridx -out test.purge.filter

test.purge.group.filter: test.purge.filter test.group.order
	line_reorder test.purge.filter test.group.order test.purge.group.filter

filters: train.purge.group.filter test.purge.group.filter

## empty implicit feedback
train.group.imfb: train.group
	pypy python/mkImfb.py train.group train.group.imfb

test.group.imfb: test.group
	pypy python/mkImfb.py test.group test.group.imfb

### features

## basic features

# make user/item feature
features/train.group.userID: train.group
	python python/mkUserID.py train.group features/train.group.userID
features/train.group.itemID: train.group
	python python/mkItemID.py train.group features/train.group.itemID

features/test.group.userID: test.group
	python python/mkUserID.py test.group features/test.group.userID
features/test.group.itemID: test.group
	python python/mkItemID.py test.group features/test.group.itemID

## sns implicit feedback

features/train.group.sns.imfb: train.group user_sns.ridx
	java -cp java/track1-lqhl.jar sns.MakeSnsImfb train.group features/train.group.sns.imfb user_sns.ridx -new_format
features/test.group.sns.imfb: test.group user_sns.ridx
	java -cp java/track1-lqhl.jar sns.MakeSnsImfb test.group features/test.group.sns.imfb user_sns.ridx -new_format

## user actions feedback
features/train.group.uaction.imfb: train.group user_action.ridx
	java -cp java/track1-lqhl.jar sns.MakeUserActionImfb train.group features/train.group.uaction.imfb user_action.ridx
features/test.group.uaction.imfb: test.group user_action.ridx
	java -cp java/track1-lqhl.jar sns.MakeUserActionImfb test.group features/test.group.uaction.imfb user_action.ridx

## sns_train feedback
features/train.group.sns_train.imfb: train.group user_sns.ridx train.ridx
	java -cp java/track1-lqhl.jar sns.MakeSnsTrainImfb train.group features/train.group.sns_train.imfb user_sns.ridx train.ridx
features/test.group.sns_train.imfb: test.group user_sns.ridx train.ridx
	java -cp java/track1-lqhl.jar sns.MakeSnsTrainImfb test.group features/test.group.sns_train.imfb user_sns.ridx train.ridx

# user profile feature, age x gender
features/train.group.uprofx62.imfb: train.group
	pypy python/mkUserProfX.py user_profile.ridx train.group features/train.group.uprofx62.imfb 6095 6 2 --imfb

features/test.group.uprofx62.imfb: test.group
	pypy python/mkUserProfX.py user_profile.ridx test.group features/test.group.uprofx62.imfb 6095 6 2 --imfb


# tags from user profile
tag.stat: user_profile.ridx
	pypy python/tagStat.py

features/train.group.tag.imfb: tag.stat user_profile.ridx train.group
	pypy python/mkTagImfb.py user_profile.ridx train.group features/train.group.tag.imfb
features/test.group.tag.imfb: tag.stat user_profile.ridx test.group
	pypy python/mkTagImfb.py user_profile.ridx test.group features/test.group.tag.imfb

# tag 200 one
features/train.group.tag200.imfb: tag.stat user_profile.ridx train.group
	pypy python/mkTagImfb.py user_profile.ridx train.group features/train.group.tag200.imfb 200
features/test.group.tag200.imfb: tag.stat user_profile.ridx test.group
	pypy python/mkTagImfb.py user_profile.ridx test.group features/test.group.tag200.imfb 200
features/train.group.tag200_one.imfb: features/train.group.tag200.imfb
	pypy python/imfb2one.py features/train.group.tag200.imfb features/train.group.tag200_one.imfb
features/test.group.tag200_one.imfb: features/test.group.tag200.imfb
	pypy python/imfb2one.py features/test.group.tag200.imfb features/test.group.tag200_one.imfb

# user keyword
train.keyw: user_key_word.ridx item.ridx train.ridx
	pypy python/analyze_keywords.py $+ $@

ukeywords.count: user_key_word.ridx
	pypy python/analyze_ukeyw_count.py $+ $@

features/train.group.ukey.imfb: user_key_word.ridx train.group $@
	pypy python/mkUserKeywFeatures.py $+ $@

features/test.group.ukey.imfb: user_key_word.ridx test.group 
	pypy python/mkUserKeywFeatures.py $+ $@

### star2000
user_sns.star.ridx: user_sns.ridx
	cpp/mkSnsStar $+ $@

features/train.group.star2000.imfb: user_sns.ridx user_sns.star.ridx train.group 
	cpp/mkStarImfb $+ $@ 2000
features/test.group.star2000.imfb: user_sns.ridx user_sns.star.ridx test.group 
	cpp/mkStarImfb $+ $@ 2000

## time h24
features/train.group.time_h24: train.group
	pypy python/mkDateTimeFeatures.py $+ $@ -h24

features/test.group.time_h24: test.group
	pypy python/mkDateTimeFeatures.py $+ $@ -h24

## item feature

# item category
itemf.cat1234:
	pypy python/mkItemCat.py item.ridx itemf.cat1234 1,2,3,4 6095

# item keywords
ikey.itemf:
	pypy python/mkItemKeyw.py user_key_word.ridx ikey.itemf 6095

ikey2000.txt: user_key_word.ridx 
	pypy python/mkCommonKeywords.py $+ $@ 2000 --only_ikey

itemf.ikey2000: user_key_word.ridx ikey2000.txt
	pypy python/mkKeywordFeatures.py $+ 2000 6095 $@ --item_feature

itemf.ikey2000.cat1234: itemf.ikey2000 itemf.cat1234
	pypy python/mergeFeatItem.py $+ $@ 2000


### experiments

# EXP 1 & 2: svdpp basic
train.purge.group.buffer: train.group train.group.imfb features/train.group.itemID features/train.group.userID train.purge.group.filter
	kddcup_combine_ugroup train.group train.purge.group.buffer -i itemID -u userID -max_block 20000 -scale_score 1 -wlist train.purge.group.filter
test.purge.group.buffer: test.group test.group.imfb features/test.group.itemID features/test.group.userID test.purge.group.filter
	kddcup_combine_ugroup test.group test.purge.group.buffer -i itemID -u userID -max_block 20000 -scale_score 1 -wlist test.purge.group.filter

purge.group.exp: train.purge.group.buffer test.purge.group.buffer
	@touch purge.group.exp

# EXP 3: uaction and sns_train

train.purge.group.uaction.sns.imfb.buffer: train.group train.group.imfb features/train.group.uaction.imfb features/train.group.sns.imfb features/train.group.itemID train.purge.group.filter
	kddcup_combine_ugroup train.group $@ -efd uaction.imfb sns.imfb -i itemID -wlist train.purge.group.filter -max_block 20000 -scale_score 1

test.purge.group.uaction.sns_train.imfb.buffer: test.group test.group.imfb features/test.group.uaction.imfb features/test.group.sns_train.imfb features/test.group.itemID test.purge.group.filter
	kddcup_combine_ugroup test.group $@ -efd uaction.imfb sns_train.imfb -i itemID -wlist test.purge.group.filter -max_block 20000 -scale_score 1

purge.group.uaction.sns_train.imfb.exp: train.purge.group.uaction.sns.imfb.buffer test.purge.group.uaction.sns_train.imfb.buffer
	@touch $@

# EXP 4: uaction, sns_train and uprof
train.purge.group.uprofx62.uaction.sns.imfb.buffer: train.group train.group.imfb features/train.group.uaction.imfb features/train.group.sns.imfb features/train.group.itemID features/train.group.uprofx62.imfb train.purge.group.filter
	kddcup_combine_ugroup train.group train.purge.group.uprofx62.uaction.sns.imfb.buffer -efd uprofx62.imfb uaction.imfb sns.imfb -i itemID -wlist train.purge.group.filter -max_block 20000 -scale_score 1

test.purge.group.uprofx62.uaction.sns_train.imfb.buffer: test.group test.group.imfb features/test.group.uaction.imfb features/test.group.sns_train.imfb features/test.group.itemID features/test.group.uprofx62.imfb test.purge.group.filter
	kddcup_combine_ugroup test.group test.purge.group.uprofx62.uaction.sns_train.imfb.buffer -efd uprofx62.imfb uaction.imfb sns_train.imfb -i itemID -wlist test.purge.group.filter -max_block 20000 -scale_score 1

purge.group.uprofx62.uaction.sns_train.imfb.exp: train.purge.group.uprofx62.uaction.sns.imfb.buffer test.purge.group.uprofx62.uaction.sns_train.imfb.buffer
	@touch purge.group.uprofx62.uaction.sns_train.imfb.exp

# EXP 5: uaction, sns_train, uprof, uprof_tag, ukey
train.purge.group.uprofx62.uaction.sns.uproftag.ukey.imfb.buffer: train.group train.group.imfb features/train.group.uaction.imfb features/train.group.sns.imfb features/train.group.tag.imfb features/train.group.ukey.imfb features/train.group.itemID features/train.group.uprofx62.imfb train.purge.group.filter
	kddcup_combine_ugroup train.group $@ -efd uprofx62.imfb uaction.imfb sns.imfb tag.imfb ukey.imfb -i itemID -wlist train.purge.group.filter -max_block 20000 -scale_score 1

test.purge.group.uprofx62.uaction.sns_train.uproftag.ukey.imfb.buffer: test.group test.group.imfb features/test.group.uaction.imfb features/test.group.sns_train.imfb features/test.group.tag.imfb features/test.group.ukey.imfb features/test.group.itemID features/test.group.uprofx62.imfb test.purge.group.filter
	kddcup_combine_ugroup test.group $@ -efd uprofx62.imfb uaction.imfb sns_train.imfb tag.imfb ukey.imfb -i itemID -wlist test.purge.group.filter -max_block 20000 -scale_score 1

purge.group.uprofx62.uaction.sns_train.uproftag.ukey.imfb.exp: train.purge.group.uprofx62.uaction.sns.uproftag.ukey.imfb.buffer test.purge.group.uprofx62.uaction.sns_train.uproftag.ukey.imfb.buffer
	@touch purge.group.uprofx62.uaction.sns_train.uproftag.ukey.imfb.exp

# EXP 5 & 6
train.purge.group.uprofx62.star2000.uproftag.uaction.sns.ukey.imfb.h24.buffer: train.group train.group.imfb features/train.group.uaction.imfb features/train.group.sns.imfb features/train.group.star2000.imfb features/train.group.ukey.imfb features/train.group.itemID features/train.group.time_h24 features/train.group.uprofx62.imfb features/train.group.tag.imfb train.purge.group.filter
	kddcup_combine_ugroup train.group $@ -efd uprofx62.imfb star2000.imfb tag.imfb uaction.imfb sns.imfb ukey.imfb -i itemID -g time_h24 -wlist train.purge.group.filter -max_block 20000 -scale_score 1

test.purge.group.uprofx62.star2000.uproftag.uaction.sns_train.ukey.imfb.h24.buffer: test.group test.group.imfb features/test.group.uaction.imfb features/test.group.sns_train.imfb features/test.group.star2000.imfb features/test.group.ukey.imfb features/test.group.itemID features/test.group.time_h24 features/test.group.uprofx62.imfb features/test.group.tag.imfb test.purge.group.filter
	kddcup_combine_ugroup test.group $@ -efd uprofx62.imfb star2000.imfb tag.imfb uaction.imfb sns_train.imfb ukey.imfb -i itemID -g time_h24 -wlist test.purge.group.filter -max_block 20000 -scale_score 1

purge.group.uprofx62.star2000.uproftag.uaction.sns_train.ukey.imfb.h24.exp: train.purge.group.uprofx62.star2000.uproftag.uaction.sns.ukey.imfb.h24.buffer test.purge.group.uprofx62.star2000.uproftag.uaction.sns_train.ukey.imfb.h24.buffer
	@touch $@
